import {API} from './config';
import CustomRequest from '@/utils/Request'

/* 
* 添加
*/
const add = async (params = {}) => {
  return CustomRequest({
    api: API.roleAdd,
    method: 'post',
    params
  })
}

/* 
* 更新
*/
const update = async (params = {}) => {
  return CustomRequest({
    api: API.roleUpdate + `?id=${params.id}`,
    method: 'post',
    params
  })
}

/* 
* 删除
*/
const del = async (id) => {
  return CustomRequest({
    api: API.roleDel,
    params: {id}
  })
}

/* 
* 分页
*/
const pageList = async (params = {}) => {
  return CustomRequest({
    api: API.rolePage,
    method: 'post',
    params
  })
}

/* 
* 详情
*/
const detail = async (id) => {
  return CustomRequest({
    api: API.roleDetail,
    params: {id}
  })
}

/* 
* 获取权限菜单
*/
const menu = async (id) => {
  return CustomRequest({
    api: !id ? API.roleMenu : API.roleMenu + `?id=${id}`
  })
}

/* 
* 获取角色列表
*/
const options = async () => {
  return CustomRequest({
    api: API.roleOption
  })
}

export {
  add,
  update,
  del,
  pageList,
  detail,
  menu,
  options
}